package com.xb.ai.exception;

import com.xb.ai.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler({BusinessException.class})
    public Result<String> businessExceptionHandler(BusinessException e) {
        log.error("【业务异常】{}", e.getMessage(), e);
        return Result.error(e.getMessage());
    }

    @ExceptionHandler({RuntimeException.class})
    public Result<String> exceptionHandler(RuntimeException e) {
        log.error("【系统异常】{}", e.getMessage(), e);
        return Result.error("系统错误，" + e.getMessage());
    }
}
